package com.yinhd.study.controller;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

/**
 * @program: study
 * @description:
 * @Author: chengl
 * @create: 2022-02-08 15:59
 **/
@Configuration
public class RestTemplateConfig {

        @Bean
        public RestTemplate restTemplate(ClientHttpRequestFactory factory){
            return new RestTemplate(factory);
        }

        @Bean
        public ClientHttpRequestFactory simpleClientHttpRequestFactory(){
            SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
            //客户端与服务端建立连接超时时间
            factory.setConnectTimeout(1000);
            //客户端从服务端读取数据的超时时间
            factory.setReadTimeout(2000);
            return factory;
        }

}
